//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __CCONDITION_H__
#define __CCONDITION_H__

#include <elasys_server.h>
#include <interlocked.h>

class CCondition : public ICondition
{
// Interface functions
//
public:
    CARAPI_(PInterface) Probe(
        /* [in]  */ REIID riid);

    CARAPI_(UInt32) AddRef();

    CARAPI_(UInt32) Release();

    CARAPI Aggregate(
        /* [in]  */ AggregateType type,
        /* [in]  */ PInterface pObject);

    CARAPI GetDomain(
        /* [out] */ PInterface * ppObject);

    CARAPI Wait(
        /* [in] */ IMutex *pMutex,
        /* [out] */ WaitResult *pResult);

    CARAPI TryWait(
        /* [in] */ IMutex *pMutex,
        /* [in] */ Millisecond32 msTimeout,
        /* [out] */ WaitResult *pResult);

    CARAPI Pulse();

    CARAPI PulseAll();


public: // static member function
    STATIC ECode S_Create(
        /* [out] */ ICondition ** ppCondition);

public:
    CCondition():m_hCondition(NULL){}
    virtual ~CCondition();
    ECode Initialize();

private:
    PVoid m_hCondition;

private:
    Interlocked m_cRef;
};

#endif //!(__CCONDITION_H__)
